﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Web;

namespace Eagle.Web
{
    /// <summary>
    /// 信息提示类
    /// </summary>
    public class Prompt
    {

        /// <summary>
        /// 输出文本提示
        /// </summary>
        /// <param name="message">要提示的信息</param>
        public static void ResponseText(string message)
        {
            ResponseText(message, true);
        }

        /// <summary>
        /// 输出文本提示
        /// </summary>
        /// <param name="message">要提示的信息</param>
        /// <param name="endResponse">是否终止流输出（true将调用Response.End()）</param>
        public static void ResponseText(string message, bool endResponse)
        {
            HttpContext.Current.Response.Clear();
            HttpContext.Current.Response.ContentType = "text/html";
            HttpContext.Current.Response.Write(message);
            if (endResponse)
                HttpContext.Current.Response.End();
        }

        /// <summary>
        /// 输出xml提示
        /// </summary>
        /// <param name="message">要提示的信息</param>
        public static void ResponseXml(string message)
        {
            ResponseXml(message, true);
        }

        /// <summary>
        /// 输出xml提示
        /// </summary>
        /// <param name="message">要提示的信息</param>
        /// <param name="endResponse">是否终止流输出（true将调用Response.End()）</param>
        public static void ResponseXml(string message, bool endResponse)
        {
            HttpContext.Current.Response.Clear();
            HttpContext.Current.Response.ContentType = "text/xml";
            HttpContext.Current.Response.Write(message);
            if (endResponse)
                HttpContext.Current.Response.End();
        }

        /// <summary>
        /// JS弹出提示，并后退到上一步
        /// </summary>
        /// <param name="message">要弹出的提示信息</param>
        /// <returns></returns>
        public static void ResponseScriptBack(string message)
        {
            ResponseText("<script language=\"javascript\" type=\"text/javascript\">alert('" + message + "');window.history.back();</script>");
        }

        /// <summary>
        /// JS弹出提示，并转到指定页
        /// </summary>
        /// <param name="message">要弹出的提示信息</param>
        /// <param name="url">要转到的URL地址</param>
        /// <returns></returns>
        public static void ResponseScriptRedirect(string message, string url)
        {
            ResponseText("<script language=\"javascript\" type=\"text/javascript\">alert('" + message + "');window.location.href='" + url + "';</script>");
        }

    }
}
